package SocialMediaSentiment;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;

import jxl.write.WriteException;

public class kFoldPosNeg2 {

	
	
	public static void main(String[] args) throws WriteException, IOException
	{
		kfoldPositiefNegatief("CorrectedTweets.xls", "CorrectedTweetsValidation.xls");
	}
	
	public static HashMap<String, String>[] kfoldPositiefNegatief(String trainfile, String testFile) throws IOException, WriteException {
		int kfold = 10;
		String tweetsFile = trainfile;
		HashMap<Integer, HashMap<String, String>[]> sets = new HashMap<Integer, HashMap<String, String>[]>();
		HashMap<Integer, HashMap<String, Float>[]> wordCounters = new HashMap<Integer, HashMap<String, Float>[]>();
		HashMap<Integer, Integer> bestWordCounter = new HashMap<Integer, Integer>();
		for (int i = 1; i <= kfold; i++) {
			// create sets: {trainset, validationset}
			HashMap<String, String>[] trainVilisetsK = createSets(tweetsFile,
					i, kfold);
			sets.put(i, trainVilisetsK);
			// create counts: {Positief, Negatief, all}
			HashMap<String, Float>[] wordCountsK = createWordCounts(trainVilisetsK[0]);
			wordCounters.put(i, wordCountsK);
		}
		for(int i = 1; i < kfold; i++)
		{
			// {testset, validationset}
			HashMap<String, String>[] setsK = sets.get(i);
			// {Positief, Negatief, all}
			HashMap<String, Float>[] wordCountersk = wordCounters.get(i);
			// {Positief, Negatief}
			float[] sentimentChance = getSentimentChance(setsK[0]);
			// classified: {Positief, Negatief, validationPositief, validationNegatief};
			HashMap<String, String>[] classifications = naiveBayes(setsK, sentimentChance, wordCountersk);
			
			HashMap<String, String>[] wrongsTrain = getWrongs(classifications[0], classifications[1]);
			HashMap<String, String>[] wrongsValidation = getWrongs(classifications[2], classifications[3]);
			
			System.out
			.println("%%%%%%%STARTING%%%%%%TRAINSET%%%%%%%%%%STARTING%%%%%%%%%%");
			System.out.println("\t\t" + "NoSentiment\t" + "Sentiment");
			System.out.println("classified:\t" + classifications[0].size() + "\t\t" + classifications[1].size());
			System.out.println("wrong:\t\t" + wrongsTrain[0].size() + "\t\t"+ wrongsTrain[1].size());
			System.out.println("||||||||||||||||||||TestSet||||||||||||||||||||");	
			System.out.println("\t\t" + "NoSentiment\t" + "Sentiment");
			System.out.println("classified:\t" + classifications[2].size() + "\t\t" + classifications[3].size());
			System.out.println("wrong:\t\t" + wrongsValidation[0].size() + "\t\t"+ wrongsValidation[1].size());
			System.out.println("||||||||||||||||||||||||||||||||||||||||||||||||");	
			
			int bestWrongs = wrongsValidation[0].size() + wrongsValidation[1].size();
			
			int failUpdates = 0;
			int bestfound = 0;
			while(failUpdates < 3)
			{
				wordCountersk = updateCounters(wrongsTrain, wordCountersk);
				classifications = naiveBayes(setsK, sentimentChance, wordCountersk);
				wrongsTrain = getWrongs(classifications[0], classifications[1]);
				wrongsValidation = getWrongs(classifications[2], classifications[3]);
				System.out
				.println("||||||||||||||||||TRAINSET||||||||||||||||||||||||");
				System.out.println("\t\t" + "NoSentiment\t" + "Sentiment");
				System.out.println("classified:\t" + classifications[0].size() + "\t\t" + classifications[1].size());
				System.out.println("wrong:\t\t" + wrongsTrain[0].size() + "\t\t"+ wrongsTrain[1].size());
				System.out.println("||||||||||||||||||||TestSet||||||||||||||||||||");	
				System.out.println("\t\t" + "NoSentiment\t" + "Sentiment");
				System.out.println("classified:\t" + classifications[2].size() + "\t\t" + classifications[3].size());
				System.out.println("wrong:\t\t" + wrongsValidation[0].size() + "\t\t"+ wrongsValidation[1].size());
				System.out.println("||||||||||||||||||||||||||||||||||||||||||||||||");	
				int totalWrongs = wrongsValidation[0].size() + wrongsValidation[1].size();
				if( totalWrongs < bestWrongs )
				{
					bestfound++;
					HashMap<String, String>[] stringarray = floattostringarray(wordCountersk);
					writeExcel.write("bestWordCounterPositief"+i+bestfound+".xls", stringarray[0]);
					writeExcel.write("bestWordCounterNegatief"+i+bestfound+".xls", stringarray[1]);
					writeExcel.write("bestWordCounterAll"+i+bestfound+".xls", stringarray[2]);
					bestWrongs = totalWrongs;
				}
				else
					failUpdates++;
			}
			/*System.out.println("####BEST####");
			wordCountersk[0]= ReadExcel.readCounters("bestWordCounterPositief"+i+bestfound+".xls", 0, 1);
			wordCountersk[1]= ReadExcel.readCounters("bestWordCounterNegatief"+i+bestfound+".xls", 0, 1);
			wordCountersk[2]= ReadExcel.readCounters("bestWordCounterAll"+i+bestfound+".xls", 0, 1);
			naiveBayes(setsK, sentimentChance, wordCountersk);*/
			bestWordCounter.put(i, bestfound);
			
		}
		HashMap<String, Float>[] averageweights = calcAverages(bestWordCounter);
		HashMap<String, String> testset = ReadExcel.readTweetSet(testFile, 0, 1);
		HashMap[] testarray = new HashMap[2];
		testarray[0] = testset;
		testarray[1] = testset;
		HashMap<String, String>[] classifications = naiveBayes(testarray, getSentimentChance(sets.get(1)[0]), averageweights);
		HashMap<String, String>[] wrongsTrain = getWrongs(classifications[0], classifications[1]);
		HashMap<String, String>[] wrongsValidation = getWrongs(classifications[2], classifications[3]);
		
		System.out
		.println("||||||||||||||||||FINALTESTSET||||||||||||||||||||||||");
		System.out.println("\t\t" + "NoSentiment\t" + "Sentiment");
		System.out.println("classified:\t" + classifications[0].size() + "\t\t" + classifications[1].size());
		System.out.println("wrong:\t\t" + wrongsTrain[0].size() + "\t\t"+ wrongsTrain[1].size());
		System.out.println("||||||||||||||||||||TestSet||||||||||||||||||||");	
		System.out.println("\t\t" + "NoSentiment\t" + "Sentiment");
		System.out.println("classified:\t" + classifications[2].size() + "\t\t" + classifications[3].size());
		System.out.println("wrong:\t\t" + wrongsValidation[0].size() + "\t\t"+ wrongsValidation[1].size());
		System.out.println("||||||||||||||||||||||||||||||||||||||||||||||||");	
		return classifications;
	}

	private static HashMap<String, String>[] getWrongs(HashMap<String, String> classiPositief,
			HashMap<String, String> classiNegatief) {
		HashMap[] wrongs = new HashMap[2];
		HashMap<String, String> wrongsPositief = new HashMap<String, String>();
		HashMap<String, String> wrongsNegatief = new HashMap<String, String>();
		Iterator<String> Positieftweets = (Iterator<String>) classiPositief.keySet().iterator();
		while(Positieftweets.hasNext())
		{
			String tweet = Positieftweets.next();
			int sentiment = Integer.parseInt(classiPositief.get(tweet).replace(" ", ""));
			if(sentiment < 0)
				wrongsPositief.put(tweet, ""+sentiment);
		}
		Iterator<String> Negatieftweets = (Iterator<String>) classiNegatief.keySet().iterator();
		while(Negatieftweets.hasNext())
		{
			String tweet = Negatieftweets.next();
			int sentiment = Integer.parseInt(classiNegatief.get(tweet).replace(" ", ""));
			if(sentiment > 0)
				wrongsNegatief.put(tweet, ""+sentiment);
		}
		wrongs[1] = wrongsPositief;
		wrongs[0] = wrongsNegatief;
		return wrongs;
	}

	private static HashMap<String, Float>[] calcAverages(
			HashMap<Integer, Integer> bestWordCounter) throws IOException {
		HashMap[] averages = new HashMap[3];
		HashMap<String, Float> averagePositief = new HashMap<String, Float>();
		HashMap<String, Float> averageNegatief = new HashMap<String, Float>();
		HashMap<String, Float> averageAll = new HashMap<String, Float>();
		Iterator<Integer> k = (Iterator<Integer>) bestWordCounter.keySet().iterator();
		int kfold = bestWordCounter.keySet().size();
		while(k.hasNext())
		{
			int key = k.next();
			HashMap<String, Float> bestcountPositief =  ReadExcel.readCounters("bestWordCounterPositief"+key+bestWordCounter.get(key)+".xls", 0, 1);
			Iterator<String> kPositief = (Iterator<String>) bestcountPositief.keySet().iterator();
			while(kPositief.hasNext())
			{
				String word = kPositief.next();
				float counter = bestcountPositief.get(word);
				float value;
				if(averagePositief.containsKey(word)){value =  averagePositief.get(word) + bestcountPositief.get(word);}else{value=bestcountPositief.get(word);}
				averagePositief.put(word, value);
			}
			HashMap<String, Float> bestcountNegatief = ReadExcel.readCounters("bestWordCounterNegatief"+key+bestWordCounter.get(key)+".xls", 0, 1);
			Iterator<String> kNegatief = (Iterator<String>) bestcountNegatief.keySet().iterator();
			while(kNegatief.hasNext())
			{
				String word = kNegatief.next();
				float counter = bestcountNegatief.get(word);
				float value;
				if(averageNegatief.containsKey(word)){value =  averageNegatief.get(word) + bestcountNegatief.get(word);}else{value=bestcountNegatief.get(word);}
				averageNegatief.put(word, value);
			}
			HashMap<String, Float> bestcountAll = ReadExcel.readCounters("bestWordCounterAll"+key+bestWordCounter.get(key)+".xls", 0, 1);
			Iterator<String> kAll = (Iterator<String>) bestcountAll.keySet().iterator();
			while(kAll.hasNext())
			{
				String word = kAll.next();
				float counter = bestcountAll.get(word);
				float value;
				if(averageAll.containsKey(word)){value =  averageAll.get(word) + bestcountAll.get(word);}else{value=bestcountAll.get(word);}
				averageAll.put(word, value);
			}
		}
		Iterator<String> kPositief = (Iterator<String>) averagePositief.keySet().iterator();
		while(kPositief.hasNext())
		{
			String word = kPositief.next();
			float counter = averagePositief.get(word);
			averagePositief.put(word, counter/kfold);
		}
		Iterator<String> kNegatief = (Iterator<String>) averageNegatief.keySet().iterator();
		while(kNegatief.hasNext())
		{
			String word = kNegatief.next();
			float counter = averageNegatief.get(word);
			averageNegatief.put(word, counter/kfold);
		}
		Iterator<String> kAll = (Iterator<String>) averageAll.keySet().iterator();
		while(kAll.hasNext())
		{
			String word = kAll.next();
			float counter = averageAll.get(word);
			averageAll.put(word, counter/kfold);
		}
		
		averages[0] = averagePositief;
		averages[1] = averageNegatief;
		averages[2] = averageAll;
		return averages;
	}

	private static HashMap<String, String>[] floattostringarray(
			HashMap<String, Float>[] wordCountersk) {
		HashMap[] returnarray = new HashMap[wordCountersk.length];
		for(int i = 0; i < wordCountersk.length; i++)
		{
			returnarray[i] = floattostringMap(wordCountersk[i]);
		}
		return returnarray;
	}

	private static HashMap<String, String> floattostringMap(HashMap<String, Float> hashMap) {
		HashMap<String, String> returnMap = new HashMap<String, String>();
		Iterator<String> k = (Iterator<String>) hashMap.keySet().iterator();
		while(k.hasNext())
		{
			String key = k.next();
			returnMap.put(key, "" + hashMap.get(key));
		}
		return returnMap;		
	}

	public static HashMap<String, String>[] naiveBayes(
			HashMap<String, String>[] sets, float[] sentimentChance,
			HashMap<String, Float>[] wordsCounts) throws IOException, WriteException {
		HashMap<String, Float> wordsCountPositief = wordsCounts[0];
		HashMap<String, Float> wordsCountNegatief = wordsCounts[1];
		HashMap<String, Float> wordsCountAll = wordsCounts[2];
		HashMap<String, String> trainSet = sets[0];
		HashMap<String, String> validationSet = sets[1];
		HashMap<String, String> classificationPositief = new HashMap<String, String>();
		HashMap<String, String> classificationNegatief = new HashMap<String, String>();
		HashMap<String, String> classificationPositiefvalidatie = new HashMap<String, String>();
		HashMap<String, String> classificationNegatiefvalidatie = new HashMap<String, String>();
		HashMap<String, String> unknowns = new HashMap<String, String>();
		
		int totalPositief = 0;
		int totalNegatief = 0;
		int totalPositiefWrong = 0;
		int totalNegatiefWrong = 0;

		float sentimentChancePositief = sentimentChance[0];
		float sentimentChanceNegatief = sentimentChance[1];
		float totalWordsPositief = getTotalCount(wordsCountPositief);
		float totalWordsNegatief = getTotalCount(wordsCountNegatief);

		Iterator<String> k = (Iterator<String>) trainSet.keySet().iterator();
		while (k.hasNext()) {
			String tweet = k.next();
			int sentiment = Integer.parseInt(trainSet.get(tweet).replace(" ",
					""));
			float posPositief = getTweetPos(tweet, wordsCountPositief, totalWordsPositief,
					sentimentChancePositief, wordsCountAll);
			float posNegatief = getTweetPos(tweet, wordsCountNegatief,
					totalWordsNegatief, sentimentChanceNegatief, wordsCountAll);
			// System.out.println(posPositief + " " + posNegatief);
			int classi = getClassification(posPositief, posNegatief);
			if(classi > 0)
				classificationPositief.put(tweet,  ""+sentiment);
			else
				classificationNegatief.put(tweet,  ""+sentiment);
						
			
		}
		

		// ///////////////////////TESTSETRUN/////////////////////////
		int totalPositiefTest = 0;
		int totalNegatiefTest = 0;
		int totalPositiefWrongTest = 0;
		int totalNegatiefWrongTest = 0;

		k = (Iterator<String>) validationSet.keySet().iterator();
		while (k.hasNext()) {
			String tweet = k.next();
			int sentiment = Integer.parseInt(validationSet.get(tweet).replace(
					" ", ""));
			float posPositief = getTweetPos(tweet, wordsCountPositief, totalWordsPositief,
					sentimentChancePositief, wordsCountAll);
			float posNegatief = getTweetPos(tweet, wordsCountNegatief,
					totalWordsNegatief, sentimentChanceNegatief, wordsCountAll);
			// System.out.println(posPositief + " " + posNegatief);
			int classi = getClassification(posPositief, posNegatief);
			if(classi > 0)
				classificationPositiefvalidatie.put(tweet, ""+sentiment);
			else
				classificationNegatiefvalidatie.put(tweet, ""+sentiment);
		

		}
		
		HashMap[] classifications = new HashMap[4];
		classifications[0] = classificationPositief;//classified 0 
		classifications[1] = classificationNegatief;//classified Negatief
		classifications[2] = classificationPositiefvalidatie;
		classifications[3] = classificationNegatiefvalidatie;
		writeExcel.write("wrongclassiPositief.xls", classificationPositiefvalidatie );
		writeExcel.write("wrongclassiNegatief.xls", classificationNegatiefvalidatie );
		writeExcel.write("unknowns.xls", unknowns);
		return classifications;

	}

	public static HashMap<String, Float>[] updateCounters(
			HashMap<String, String>[] wrongTweets,
			HashMap<String, Float>[] wordCounters) {
		
		HashMap<String, Float>[] returnwordCounters = wordCounters.clone();
		for (int i = 0; i < 2; i++) {
			HashMap<String, String> wrongTweetClassi = wrongTweets[i];
			HashMap<String, Float> wordCount = returnwordCounters[i];
			Iterator<String> k2 = (Iterator<String>) wrongTweetClassi.keySet()
					.iterator();
			while (k2.hasNext()) {
				String tweet = k2.next();
				StringTokenizer tokenizer = new StringTokenizer(tweet, " ");
				while (tokenizer.hasMoreTokens()) {
					String word = tokenizer.nextToken();
					Float value;
					if (wordCount.containsKey(word)) {
						value = wordCount.get(word) + 1;
					} else {
						value = (float) 1;
					}
					wordCount.put(word, value);
				}
			}
			returnwordCounters[i] = wordCount;
		}
		return returnwordCounters;
	}

	public static int getClassification(float Positief, float Negatief) {
		int classification = 1;
		if (Negatief > Positief)
			classification = -1;
		return classification;
	}

	public static float getTweetPos(String tweet,
			HashMap<String, Float> wordsCount, float totalWords,
			float sentimentChance, HashMap<String, Float> wordsCountAll) {
		StringTokenizer tokenizer = new StringTokenizer(tweet);
		Float chance;
		float tweetPos = sentimentChance;
		// float words = tokenizer.countTokens();
		// tweetPos = 0;
		while (tokenizer.hasMoreTokens()) {
			String word = tokenizer.nextToken();
			if (wordsCountAll.keySet().contains(word)) {
				try {
					chance = (wordsCount.get(word)) / totalWords;
				} catch (NullPointerException e) {
					chance = 1 / totalWords;
				}

				// System.out.println(chance + "  " + tweetPos + "   " + word);
				tweetPos = tweetPos * chance * 1000;
			}
		}
		return tweetPos;
	}

	public static HashMap<String, Float> getWordsCount(String file)
			throws IOException {
		HashMap<String, Float> wordsCount = new HashMap<String, Float>();
		HashMap<Integer, String[]> IndexWordsCounter = ReadExcel.read(file, 0,
				1);
		Iterator<Integer> k = (Iterator<Integer>) IndexWordsCounter.keySet()
				.iterator();
		while (k.hasNext()) {
			int index = k.next();
			String[] WordsCounter = IndexWordsCounter.get(index);
			String word = WordsCounter[0];
			float count = Float.parseFloat(WordsCounter[1]);
			wordsCount.put(word, (count + 1));
		}
		return wordsCount;
	}

	public static float getTotalCount(HashMap<String, Float> wordsCount)
			throws IOException {
		float total = 0;
		Iterator<String> k = (Iterator<String>) wordsCount.keySet().iterator();
		total += wordsCount.keySet().size();
		while (k.hasNext()) {
			String word = k.next();
			float count = wordsCount.get(word);
			total += count;
		}
		return total;
	}

	public static float[] getSentimentChance(HashMap<String, String> tweets)
			throws IOException {
		float[] sentimentChance = new float[2];
		float Positief = 0;
		float Negatief = 0;
		float total = 0;

		Iterator<String> k = (Iterator<String>) tweets.keySet().iterator();
		while (k.hasNext()) {
			String tweet = k.next();
			int TweetSentiment = Integer.parseInt(tweets.get(tweet).replace(
					" ", ""));
			;
			if (TweetSentiment < 0)
			{
				Negatief++;
				total++;
			}
			else if( TweetSentiment > 0)
			{
				Positief++;
				total++;
			}
			
		}
		sentimentChance[0] = Positief / total;
		sentimentChance[1] = Negatief / total;
		return sentimentChance;

	}

	public static HashMap<String, String>[] createSets(String alltweetsFile,
			int times, int kfold) throws IOException {

		HashMap<Integer, String[]> tweetsWithSentiment = ReadExcel.read(
				alltweetsFile, 0, 1);
		int maxindex = tweetsWithSentiment.size() - 1;
		Iterator<Integer> k = (Iterator<Integer>) tweetsWithSentiment.keySet()
				.iterator();
		HashMap<String, String> trainSet = new HashMap<String, String>();
		HashMap<String, String> validationSet = new HashMap<String, String>();

		while (k.hasNext()) {
			int index = k.next();
			String[] tweetSentiment = tweetsWithSentiment.get(index);

			if (index < (maxindex - (maxindex / kfold * times))
					|| index > (maxindex - (maxindex / kfold * (times - 1)))) {
				trainSet.put(tweetSentiment[0], tweetSentiment[1]);
			} else {
				validationSet.put(tweetSentiment[0], tweetSentiment[1]);
			}
		}
		HashMap[] kfoldSets = new HashMap[2];
		kfoldSets[0] = trainSet;
		kfoldSets[1] = validationSet;

		return kfoldSets;
	}

	public static HashMap<String, Float>[] createWordCounts(
			HashMap<String, String> trainSet) {
		HashMap[] counters = new HashMap[3];
		HashMap<String, Float> wordsCountAll = new HashMap<String, Float>();
		HashMap<String, Float> wordsCountPositief = new HashMap<String, Float>();
		HashMap<String, Float> wordsCountNegatief = new HashMap<String, Float>();
		Iterator<String> k2 = (Iterator<String>) trainSet.keySet().iterator();
		while (k2.hasNext()) {
			String tweet = k2.next();
			int sentiment = Integer.parseInt(trainSet.get(tweet).replace(" ",
					""));
			StringTokenizer st = new StringTokenizer(tweet,
					" \r\n\t\f,.!$%^&*()[]{}-=\\;<>/?");
			if (sentiment > 0) {
				while (st.hasMoreTokens()) {
					String key = st.nextToken();
					float value;
					if (wordsCountPositief.containsKey(key)) {
						value = wordsCountPositief.get(key) + 1;
					} else {
						value = 1;
					}
					wordsCountPositief.put(key, value);
					if (wordsCountAll.containsKey(key)) {
						value = wordsCountAll.get(key) + 1;
					} else {
						value = 1;
					}
					wordsCountAll.put(key, value);
				}
			} else if(sentiment < 0) {
				while (st.hasMoreTokens()) {
					String key = st.nextToken();
					float value;
					if (wordsCountNegatief.containsKey(key)) {
						value = wordsCountNegatief.get(key) + 1;
					} else {
						value = 1;
					}
					wordsCountNegatief.put(key, value);
					if (wordsCountAll.containsKey(key)) {
						value = wordsCountAll.get(key) + 1;
					} else {
						value = 1;
					}
					wordsCountAll.put(key, value);
				}
			}
		}
		counters[0] = wordsCountPositief;
		counters[1] = wordsCountNegatief;
		counters[2] = wordsCountAll;
		return counters;
	}
	public static HashMap<String, Float>[] createWordCountsAda(
			HashMap<String, String> trainSet) {
		HashMap[] counters = new HashMap[3];
		HashMap<String, Float> wordsCountAll = new HashMap<String, Float>();
		HashMap<String, Float> wordsCountPositief = new HashMap<String, Float>();
		HashMap<String, Float> wordsCountNegatief = new HashMap<String, Float>();
		Iterator<String> k2 = (Iterator<String>) trainSet.keySet().iterator();
		while (k2.hasNext()) {
			String tweet = k2.next();
			int sentiment = Integer.parseInt(trainSet.get(tweet).replace(" ",
					""));
			StringTokenizer st = new StringTokenizer(tweet,
					" \r\n\t\f,.!$%^&*()[]{}-=\\;<>/?");
			if (sentiment == 0) {
				while (st.hasMoreTokens()) {
					String key = st.nextToken();
					float value;
					if (wordsCountPositief.containsKey(key)) {
						value = wordsCountPositief.get(key) + 1;
					} else {
						value = 1;
					}
					wordsCountPositief.put(key, value);
					if (wordsCountAll.containsKey(key)) {
						value = wordsCountAll.get(key) + 1;
					} else {
						value = 1;
					}
					wordsCountAll.put(key, value);
				}
			} else {
				while (st.hasMoreTokens()) {
					String key = st.nextToken();
					float value;
					if (wordsCountNegatief.containsKey(key)) {
						value = wordsCountNegatief.get(key) + 1;
					} else {
						value = 1;
					}
					wordsCountNegatief.put(key, value);
					if (wordsCountAll.containsKey(key)) {
						value = wordsCountAll.get(key) + 1;
					} else {
						value = 1;
					}
					wordsCountAll.put(key, value);
				}
			}
		}
		
		Iterator<String> wcall = (Iterator<String>) wordsCountAll.keySet().iterator();
		while(wcall.hasNext())
		{
			String word = wcall.next();
			if( wordsCountPositief.containsKey(word) && wordsCountNegatief.containsKey(word))
			{
				System.out.println(word);
				float wcz = wordsCountPositief.get(word);
				float wcnz = wordsCountNegatief.get(word);
				if(wcz > wcnz)
				{
					wcz = wcz - wcnz;
					wcnz = 1;
				}
				else
				{
					wcnz = wcnz - wcz;
					wcz = 1;
				}
				wordsCountPositief.put(word, wcz);
				wordsCountNegatief.put(word, wcnz);
				wordsCountAll.put(word, Math.abs(wcz-wcnz));
			}
		}
		
		counters[0] = wordsCountPositief;
		counters[1] = wordsCountNegatief;
		counters[2] = wordsCountAll;
		return counters;
	}

}
